package cn.iocoder.yudao.module.member.eid.controller.admin;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.api.member.eid.vo.EidVO;
import cn.iocoder.yudao.module.member.eid.dal.dataobject.MemberEidDO;
import cn.iocoder.yudao.module.member.eid.service.MemberEidService;
import cn.iocoder.yudao.module.member.eid.vo.EidAuditReqVO;
import cn.iocoder.yudao.module.member.eid.vo.EidPageReqVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 实名信息")
@RestController
@RequestMapping("/member/idcard")
@Validated
public class MemberEidController {

    @Resource
    private MemberEidService memberEidService;

    @PostMapping("/audit")
    @Operation(summary = "审核实名信息")
    public CommonResult<Boolean> saveIdcard(@Valid @RequestBody EidAuditReqVO reqVO) {
        memberEidService.updateAudit(reqVO);
        return success(true);
    }

    @GetMapping("/page")
    @Operation(summary = "获得实名信息分页")
    @PreAuthorize("@ss.hasPermission('member:idcard:query')")
    public CommonResult<PageResult<EidVO>> getIdcardPage(@Valid EidPageReqVO pageReqVO) {
        PageResult<MemberEidDO> pageResult = memberEidService.getIdcardPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, EidVO.class));
    }

}
